import { http } from '../http';
import type { ApiResponse } from '~/api/types/http';
import type {
  ConsultRecord,
  CreateConsultParams,
  ConsultListQuery,
  ConsultListResponse,
  ConsultListParams,
  ConsultItem,
} from '~/api/types/consult';

/**
 * 咨询API组合函数
 */
export const useConsultApi = () => {
  /**
   * 获取咨询列表
   * @param params 查询参数
   * @returns useFetch 响应对象
   */
  const getConsultList = (params: ConsultListParams = {}) =>
    http.get<ConsultListResponse>('/consult/list', { query: params });

  /**
   * 创建咨询
   * @param params 创建参数
   * @returns useFetch 响应对象
   */
  const createConsult = (params: CreateConsultParams) =>
    http.post<ConsultItem>('/consult/create', params);

  /**
   * 获取咨询详情
   * @param consultId 咨询ID
   * @returns useFetch 响应对象
   */
  const getConsultDetail = (consultId: string) =>
    http.get<ConsultItem>(`/consult/${consultId}`);

  /**
   * 更新咨询状态
   * @param consultId 咨询ID
   * @param status 状态
   * @returns useFetch 响应对象
   */
  const updateConsultStatus = (consultId: string, status: string) =>
    http.put<ConsultItem>(`/consult/${consultId}/status`, { status });

  /**
   * 删除咨询
   * @param consultId 咨询ID
   * @returns useFetch 响应对象
   */
  const deleteConsult = (consultId: string) =>
    http.delete(`/consult/${consultId}`);

  return {
    getConsultList,
    createConsult,
    getConsultDetail,
    updateConsultStatus,
    deleteConsult,
  };
};
